var async = require("async");
var renderEngin = require("../common/renderEngin");
exports.index = function(req, res) {
    use(["public/javascripts/index/init.js", "public/javascripts/service/indexService.js"], function(PageComponent, IndexService) {
        var storage = {};
        function getNewOrders(done) {
			IndexService.getNewOrders(function (res) {
                if(res.errorCode === 0) {
                   done(null, res.data);
                }
            });
        };
        function getCusOrders(done) {
        	IndexService.getCusOrders(function (res) {
                if(res.errorCode === 0) {
                   done(null, res.data);
                }
            });
        }
        async.parallel({
                newOrders: getNewOrders,
                cusOrders: getCusOrders
            }, function (err, result) {
            	storage["newOrders"] = result.newOrders;
            	storage["cusOrders"] = result.cusOrders;
            	PageComponent = React.createFactory(PageComponent);
        		renderEngin.call(res, 'index', PageComponent, storage);		
    	});
		// storage["newOrders"] = [];
		// storage["cusOrders"] = [];
		// PageComponent = React.createFactory(PageComponent);
		// renderEngin.call(res, 'index', PageComponent, storage);
    });
 }
